package com.lxs.mall.controller;

import com.github.pagehelper.PageInfo;
import com.lxs.mall.common.ApiRestResponse;
import com.lxs.mall.model.vo.OrderStatisticsVo;
import com.lxs.mall.service.OrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author 小松
 */
@RestController
public class OrderAdminController {
    @Resource
    OrderService orderService;

    @ApiOperation("后台订单列表")
    @GetMapping("/admin/order/list")
    public ApiRestResponse list(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        PageInfo pageInfo = orderService.listForAdmin(pageNum, pageSize);
        return ApiRestResponse.success(pageInfo);
    }

    @ApiOperation("后台订单发货")
    @PostMapping("/admin/order/delivered")
    public ApiRestResponse delivered(@RequestParam String orderNo) {
        orderService.delivered(orderNo);
        return ApiRestResponse.success();
    }

    @ApiOperation("订单完结")
    @PostMapping("/order/finish")
    public ApiRestResponse finish(@RequestParam String orderNo) {
        orderService.finish(orderNo);
        return ApiRestResponse.success();
    }

    @ApiOperation("每日订单统计")
    @GetMapping("/admin/order/statistics")
    public ApiRestResponse statistics(@RequestParam
                                      @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                                      @RequestParam
                                      @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        List<OrderStatisticsVo> orderStatisticsVos = orderService.statistics(startDate, endDate);
        return ApiRestResponse.success(orderStatisticsVos);
    }
}
